package 剑指offer;

import java.util.Arrays;

public class QucikSort {
    public static void quickSort01(int[] data, int start, int end) {
        if (start > end) {
            return;
        }
        int left = start;
        int right = end;
        int temp = data[left];
        while (left < right) {
            while (left<right && temp<=data[right]) {
                right--;
            }
            while (left<right && temp>=data[left]) {
                left++;
            }
            temp = data[left];
            data[left] = data[right];
            data[right] = temp;
        }
        data[left] = data[start];
        data[start] = temp;
        quickSort01(data, start, left-1);
        quickSort01(data, left+1, end);
    }

    public static void main(String[] args) {
        int[] arr = {2, 5, 1, 4, 3, 6, 8, 7};
        quickSort01(arr, 0, arr.length-1);
        System.out.println(Arrays.toString(arr));
    }
}
